Be sure to include dev-deps for doctests with --extern
authorAlex Crichton <alex@alexcrichton.com>
Thu, 2 Apr 2015 18:51:29 +0000 (11:51 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 2 Apr 2015 18:51:29 +0000 (11:51 -0700)
Previously the "add immediate deps" logic bailed out too soon and didn't pick up
all dev-dependencies.

Closes #1474

src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_test.rs

index 0415a9c7c3e3984ad58d16e6a56108163df9fdca..d8d14820c13e948e02f624a5b01192b78644f4dc 100644 (file)
@@ -143,23 +143,23 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
                 let pkgid = pkg.package_id().clone();
                 cx.compilation.libraries.entry(pkgid).or_insert(Vec::new())
                   .push((target.crate_name(), dst));
-                if !target.is_lib() { continue }
+            }
+            if !target.is_lib() { continue }
 
-                // Include immediate lib deps as well
-                for dep in cx.dep_targets(pkg, target, profile).iter() {
-                    let (pkg, target, profile) = *dep;
-                    let pkgid = pkg.package_id();
-                    if !target.is_lib() { continue }
-                    if profile.doc { continue }
-                    if cx.compilation.libraries.contains_key(&pkgid) { continue }
-
-                    let v = try!(cx.target_filenames(target, profile));
-                    let v = v.into_iter().map(|f| {
-                        (target.crate_name(),
-                         cx.out_dir(pkg, Kind::Target, target).join(f))
-                    }).collect::<Vec<_>>();
-                    cx.compilation.libraries.insert(pkgid.clone(), v);
-                }
+            // Include immediate lib deps as well
+            for dep in cx.dep_targets(pkg, target, profile).iter() {
+                let (pkg, target, profile) = *dep;
+                let pkgid = pkg.package_id();
+                if !target.is_lib() { continue }
+                if profile.doc { continue }
+                if cx.compilation.libraries.contains_key(&pkgid) { continue }
+
+                let v = try!(cx.target_filenames(target, profile));
+                let v = v.into_iter().map(|f| {
+                    (target.crate_name(),
+                     cx.out_dir(pkg, Kind::Target, target).join(f))
+                }).collect::<Vec<_>>();
+                cx.compilation.libraries.insert(pkgid.clone(), v);
             }
         }
     }
index 6cf457aee0a25cd6aad58ace0d88480916ba8b00..eb129202fad88c69e6d51453107cc9e129bc701b 100644 (file)
@@ -1419,3 +1419,32 @@ test!(dashes_to_underscores {
     assert_that(p.cargo_process("test").arg("-v"),
                 execs().with_status(0));
 });
+
+test!(doctest_dev_dep {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dev-dependencies]
+            b = { path = "b" }
+        "#)
+        .file("src/lib.rs", r#"
+            /// ```
+            /// extern crate b;
+            /// ```
+            pub fn foo() {}
+        "#)
+        .file("b/Cargo.toml", r#"
+            [package]
+            name = "b"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("b/src/lib.rs", "");
+
+    assert_that(p.cargo_process("test").arg("-v"),
+                execs().with_status(0));
+});